package com.dycx.api.controller.manage.cms;

import com.dycx.cms.dto.AdTypeDTO;
import com.dycx.cms.service.AdTypeService;
import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController
@RequestMapping(value = "/manage/cms/adType")
public class AdTypeController {

    @Resource
    private AdTypeService adTypeService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD_TYPE, bizValue = "{#adTypeDto.id}",logTitle = "添加广告分类")
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody @Valid AdTypeDTO adTypeDto) {
        return adTypeService.add(adTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD_TYPE, bizValue = "{#adTypeDto.id}",logTitle = "修改广告分类")
    @PostMapping("/edit")
    public RestResponse<?> edit(@RequestBody @Valid AdTypeDTO adTypeDto) {
        return adTypeService.edit(adTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD_TYPE, bizValue = "{#typeId}",logTitle = "删除广告分类")
    @GetMapping("/delete")
    public RestResponse<?> delete(int id) {
        return adTypeService.delete(id) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 查询 根据主键 id 查询
     **/
    @GetMapping("/getAllList")
    public RestResponse<?> getAllList() {
        return RestResponse.success(adTypeService.getAllList(0));
    }

    /**
     * 修改排序
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD_TYPE, bizValue = "{#adTypeDTO.id}",logTitle = "更新广告分类排序")
    @PostMapping("/updateSort")
    public RestResponse<?> updateSort(@RequestBody AdTypeDTO adTypeDTO) {
        return RestResponse.success(adTypeService.updateSort(adTypeDTO));
    }

    /**
     * 修改状态
     **/
    @WriterLog(bizType = BizTypeEnum.CMS_AD_TYPE, bizValue = "{#adTypeDTO.id}",logTitle = "更新广告分类状态")
    @PostMapping("/updateStatus")
    public RestResponse<?> updateStatus(@RequestBody AdTypeDTO adTypeDTO) {
        return RestResponse.success(adTypeService.updateStatus(adTypeDTO));
    }
}
